#ifndef __UEQ_SERIAL_H_INCLUDED__
#define __UEQ_SERIAL_H_INCLUDED__

#include "ueq_eq.h"
#include "ueq_fifo.h"

typedef BYTE (*UeqSerialRxByteFunc)(void);
typedef void (*UeqSerialTxByteFunc)(BYTE);

typedef struct UeqSerialRxStruct
{
    UeqEventQueue          *event_queue;
    UeqFifo                 buffer;
    UeqSerialRxByteFunc     rx_byte_func;
    UeqEvent                event;
} UeqSerialRx;

typedef struct UeqSerialTxStruct
{
    UeqEventQueue          *event_queue;
    UeqFifo                 buffer;
    UeqSerialTxByteFunc     tx_byte_func;
    UeqEvent                event;
    BOOL                    is_transmitting;
} UeqSerialTx;

void ueq_serial_rx_init(
    UeqSerialRx            *serial,
    UeqEventQueue          *event_queue,
    UeqSerialRxByteFunc     rx_byte_func,
    UeqEvent                event,
    BYTE                   *buffer,
    INT32                   buffer_size);

void ueq_serial_tx_init(
    UeqSerialTx            *serial,
    UeqEventQueue          *event_queue,
    UeqSerialTxByteFunc     tx_byte_func,
    UeqEvent                event,
    BYTE                   *buffer,
    INT32                   buffer_size);

void ueq_serial_rx_isr_handler(UeqSerialRx *serial);
void ueq_serial_tx_isr_handler(UeqSerialTx *serial);

void ueq_serial_tx_write(UeqSerialTx *serial, BYTE *buffer, INT32 size);

#endif /* __UEQ_SERIAL_H_INCLUDED__ */
